//
// Created by mabinjie on 2024/10/28.
//

#ifndef TCOMMON_RESPONSE_HPP
#define TCOMMON_RESPONSE_HPP
#include <cstdint>

#include "common/serializer.hpp"
#include "protocol/message/jtt808_body.hpp"


namespace protocol::terminal {

enum class ResponseResult : uint8_t {
    SUCCESS = 0,
    FAIL = 1,
    MESSAGE_ERROR = 2,
    NOT_SUPPORT = 3
};


class CommonResponse final : public jtt808_body {
public:
    uint16_t message_sn_to_response_{};
    uint16_t message_id_to_response_{};
    uint8_t result_{};

    IMPLEMENT_SIZEABLE(message_sn_to_response_, message_id_to_response_, result_);
    IMPLEMENT_TOSTRING(message_id_, message_sn_to_response_, message_id_to_response_, result_)

    CommonResponse() : jtt808_body(0x0001) {}

    CommonResponse(const uint16_t message_sn_to_response, const uint16_t message_id_to_response, const ResponseResult result)
        : jtt808_body(0x0001), message_sn_to_response_(message_sn_to_response),
          message_id_to_response_(message_id_to_response),
          result_(static_cast<uint8_t>(result)) {
    }

    CommonResponse(const CommonResponse &other) = default;

    CommonResponse(CommonResponse &&other) noexcept = default;

    CommonResponse & operator=(const CommonResponse &other) = default;

    CommonResponse & operator=(CommonResponse &&other) noexcept = default;

    void serialize(common::MessagePackWriter &writer) override {
        APPLY(writer.writeUint,;, message_sn_to_response_, message_id_to_response_, result_);
    }

    void deserialize(common::MessagePackReader &reader) override {
        APPLY(reader.readUint,;, message_sn_to_response_, message_id_to_response_, result_);
    }
};

}


#endif //COMMON_RESPONSE_HPP
